package com.lmolong.controller;

import com.lmolong.authbean.AuthUserDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import com.lmolong.pojo.TUser;

@RestController
public class UserController {
    @Autowired
    private TokenStore tokenStore;

    @PostMapping("/auth")
    public String auth(@RequestHeader("Authorization") String auth){
        AuthUserDetail authUserDetail = (AuthUserDetail) tokenStore.readAuthentication(auth.split(" ")[1]).getPrincipal();
        TUser tUser = authUserDetail.getTUser();
        return tUser.getUsername()+":"+tUser.getPassword();
    }
}
